package com.qf.wangqing.sportsnews.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.qf.wangqing.sportsnews.R;
import com.qf.wangqing.sportsnews.adapter.matchsecond.MatchsecondpagerAdapter;
import com.qf.wangqing.sportsnews.bean.cornpetition.cornpeitionbean.CornpetitionRootEntity;
import com.qf.wangqing.sportsnews.callback.CompetitionService;
import com.qf.wangqing.sportsnews.databinding.ActivityMatchSecondBinding;
import com.qf.wangqing.sportsnews.fragment.matchsecond.MatchChatFragment;
import com.qf.wangqing.sportsnews.fragment.matchsecond.MatchDataFragment;
import com.qf.wangqing.sportsnews.fragment.matchsecond.MatchTelecastFragment;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MatchSecondActivity extends AppCompatActivity  {

  private ActivityMatchSecondBinding binding;
    private List<Fragment> matchfragmentList;
    private ViewPager matchviewPager;
    private CompetitionService competitionService;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.activity_match_second);
        binding= DataBindingUtil.setContentView(this,R.layout.activity_match_second);
        initView();

      Download();
    }

    private void Download() {
        competitionService=new Retrofit.Builder()
                .baseUrl("http://www.baidu")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(CompetitionService.class);

        competitionService.getWords().enqueue(new Callback<CornpetitionRootEntity>() {
            @Override
            public void onResponse(Call<CornpetitionRootEntity> call, Response<CornpetitionRootEntity> response) {
                Log.d("1620", "onCreate: 11111111111");
                CornpetitionRootEntity body=response.body();
                binding.setMain(body.getData().getContest_full());
            }

            @Override
            public void onFailure(Call<CornpetitionRootEntity> call, Throwable t) {

            }
        });

//        MyApplication application= (MyApplication) getApplication();
//        application.getCompetitionService().getWords().enqueue(this);
    }


    private void initView() {
        matchfragmentList = new ArrayList<Fragment>();
        matchfragmentList.add(new MatchTelecastFragment());
        matchfragmentList.add(new MatchDataFragment());
        matchfragmentList.add(new MatchChatFragment());
        matchviewPager = (ViewPager) findViewById(R.id.match_second_pager);
        MatchsecondpagerAdapter adapter
                = new MatchsecondpagerAdapter(getSupportFragmentManager(),matchfragmentList);
        matchviewPager.setAdapter(adapter);
        TabLayout tab = (TabLayout) findViewById(R.id.match_second_tab);
        tab.setupWithViewPager(matchviewPager);
    }


}
